![]() |
Kinetis SDK API Reference Manual
1.0.0-beta
Freescale Semiconductor, Inc.
|
The section describes the programming interface of the PIT Peripheral driver. More...
Data Structures | |
| struct | pit_user_config_t |
| PIT timer configuration structure. More... | |
Typedefs | |
| typedef void(* | pit_isr_callback_t )(void) |
| PIT ISR callback function typedef. | |
Initialize and Shutdown | |
| void | pit_init_module (bool isRunInDebug) |
| Initialize PIT module. More... | |
| void | pit_init_channel (uint32_t timer, const pit_user_config_t *config) |
| Initialize PIT channel. More... | |
| void | pit_shutdown (void) |
| Disable PIT module and gate control. More... | |
Timer Start and Stop | |
| void | pit_timer_start (uint32_t timer) |
| Start timer counting. More... | |
| void | pit_timer_stop (uint32_t timer) |
| Stop timer counting. More... | |
Timer Period | |
| void | pit_set_timer_period_us (uint32_t timer, uint32_t us) |
| Set timer period in microsecond units. More... | |
| uint32_t | pit_read_timer_us (uint32_t timer) |
| Read current timer value in microsecond units. More... | |
ISR Callback Function | |
| void | pit_register_isr_callback_function (uint32_t timer, pit_isr_callback_t function) |
| Register pit isr callback function. More... | |
| struct pit_user_config_t |
Define structure PitConfig and use pit_init_channel() to make necessary initializations. You may also use remaining functions for PIT configuration.
Data Fields | |
| bool | isInterruptEnabled |
| Timer interrupt 0-disable/1-enable. | |
| bool | isTimerChained |
| Chained with previous timer, 0-not/1-chained. | |
| uint32_t | periodUs |
| Timer period in unit of microseconds. | |
| void pit_init_module | ( | bool | isRunInDebug | ) |
This function must be called before calling all the other PIT driver functions. This function un-gates the PIT clock and enables the PIT module. The isRunInDebug passed into function will affect all timer channels.
| isRunInDebug | Timers run or stop in debug mode.
|
| void pit_init_channel | ( | uint32_t | timer, |
| const pit_user_config_t * | config | ||
| ) |
This function initialize PIT timers by channel. Pass in timer number and its config structure. Timers do not start counting by default after calling this function. Function pit_timer_start must be called to start timer counting. Call pit_set_timer_period_us to re-set the period.
Here is an example demonstrating how to define a PIT channel config structure:
| timer | Timer channel number. |
| config | PIT channel configuration structure. |
| void pit_shutdown | ( | void | ) |
This function disables all PIT interrupts and PIT clock. It then gates the PIT clock control. pit_init_module must be called if you want to use PIT again.
| void pit_timer_start | ( | uint32_t | timer | ) |
After calling this function, timers load period value, count down to 0 and then load the respective start value again. Each time a timer reaches 0, it generates a trigger pulse and sets the timeout interrupt flag.
| timer | Timer channel number. |
| void pit_timer_stop | ( | uint32_t | timer | ) |
This function stops every timer counting. Timers reload their periods respectively after the next time they call pit_timer_start.
| timer | Timer channel number. |
| void pit_set_timer_period_us | ( | uint32_t | timer, |
| uint32_t | us | ||
| ) |
The period range depends on the frequency of PIT source clock. If the required period is out of range, use the lifetime timer, if applicable.
| timer | Timer channel number. |
| us | Timer period in microseconds. |
| uint32_t pit_read_timer_us | ( | uint32_t | timer | ) |
This function returns an absolute time stamp in microsecond units. One common use of this function is to measure the running time of a part of code. Call this function at both the beginning and end of code; the time difference between these two time stamps is the running time (Make sure the running time will not exceed the timer period). The time stamp returned is up-counting.
| timer | Timer channel number. |
| void pit_register_isr_callback_function | ( | uint32_t | timer, |
| pit_isr_callback_t | function | ||
| ) |
System default ISR interfaces are already defined in fsl_pit_irq.c. Users can either edit these ISRs or use this function to register a callback function. The default ISR runs the callback function if there is one installed.
| timer | Timer channel number. |
| function | Pointer to pit isr callback function. |